package com.dabai.iot.mqtt.server.verticle;

import com.dabai.iot.mqtt.server.VertxWebSocketServer;
import io.vertx.core.Deployable;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.function.Supplier;

import static org.springframework.beans.factory.config.AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE;

/**
 * 提供 VertxWebSocketServer 实例的 Supplier
 *
 * @author kev1n
 */
@Component
public class WebSocketVerticleSupplier implements Supplier<Deployable> {

    @Resource
    private ApplicationContext context;

    /**
     * 获取 VertxWebSocketServer 实例
     *
     * @return 通过 Spring 容器创建并注入依赖的 VertxWebSocketServer 实例
     */
    @Override
    public VertxWebSocketServer get() {
        return (VertxWebSocketServer) context.getAutowireCapableBeanFactory()
            .autowire(VertxWebSocketServer.class, AUTOWIRE_BY_TYPE, true);
    }
}
